//
//  HeadView.m
//  WhereToTravel
//
//  Created by dlios on 15/10/13.
//  Copyright © 2015年 zhoushengmin. All rights reserved.
//

#import "HeadView.h"

@implementation HeadView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(night) name:@"night" object:nil];
        
        [self creatView];
    }
    return self;
}

- (void)creatView {
    self.backImage = [[UIImageView alloc]init];
    self.backImage.frame = CGRectMake(0, 0, WIDTH * 375, self.bounds.size.height * 0.8);
    [self addSubview:self.backImage];
    
    [self.backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.equalTo(self.mas_height).multipliedBy(0.8);
    }];
    
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.frame = CGRectMake(0, self.bounds.size.height * 0.8, WIDTH * 375, self.bounds.size.height * 0.2);
    [self addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    self.buttonAsia = [UIButton buttonWithType:UIButtonTypeSystem];
   
    self.buttonOceania = [UIButton buttonWithType:UIButtonTypeSystem];
    
    self.buttonAntarctica = [UIButton buttonWithType:UIButtonTypeSystem];
   
    self.buttonEurope = [UIButton buttonWithType:UIButtonTypeSystem];
 
    self.buttonAfrika = [UIButton buttonWithType:UIButtonTypeSystem];
  
    self.buttonSouthAmerica = [UIButton buttonWithType:UIButtonTypeSystem];
   
    self.buttonNorthAmerica = [UIButton buttonWithType:UIButtonTypeSystem];
  
    self.buttonAsia.frame = CGRectMake(250 * WIDTH, HEIGHT * 40, WIDTH * 40, HEIGHT * 40);
    self.buttonEurope.frame=CGRectMake(200 * WIDTH, 40 * HEIGHT, WIDTH * 40, HEIGHT * 20);
    self.buttonNorthAmerica.frame=CGRectMake(50 * WIDTH, 30 * HEIGHT, 55 * WIDTH,HEIGHT * 20);
    self.buttonSouthAmerica.frame = CGRectMake(90 * WIDTH,HEIGHT * 120,WIDTH * 55, HEIGHT * 20);
    self.buttonOceania.frame=CGRectMake(WIDTH * 290, HEIGHT * 160,WIDTH * 55, HEIGHT * 20);
    self.buttonAfrika.frame=CGRectMake(WIDTH * 180, HEIGHT * 100,WIDTH * 40, HEIGHT * 20);
    self.buttonAntarctica.frame = CGRectMake(WIDTH * 200,HEIGHT * 220,WIDTH * 55, HEIGHT * 20);
    [self.backImage addSubview:self.buttonAsia];
    [self.backImage addSubview:self.buttonOceania];
    [self.backImage addSubview:self.buttonAntarctica];
    [self.backImage addSubview:self.buttonEurope];
    [self.backImage addSubview:self.buttonAfrika];
    [self.backImage addSubview:self.buttonSouthAmerica];
    [self.backImage addSubview:self.buttonNorthAmerica];
   
}


- (void)night {
    if ([SingletonNight shareSingletonNight].isSelete == YES) {
        self.titleLabel.textColor = [UIColor whiteColor];
    }
    else {
        self.titleLabel.textColor = [UIColor blackColor];
    }
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"night" object:nil];
}



@end
